<!doctype html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<meta name="author" content="yinq">
<title>{if $title}{$title} - {/if}光年文档管理系统(Light Year Doc)</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
{load href="/static/css/materialdesignicons.min.css,/static/css/bootstrap.min.css,/static/css/animate.min.css"}
{load href="/static/js/jquery-confirm/jquery-confirm.min.css,/static/css/app.min.css,/admin/css/admin.min.css"}
{load href="/static/js/jstree/themes/default/style.css" /}
{load href="/static/js/editormd/css/editormd.min.css,/admin/css/manual.min.css" /}
{load href="/static/js/jquery.min.js,/static/js/bootstrap-notify.min.js" /}
<script type="text/javascript">
    window.CONFIG = {
        "manual_id" : "{$manual_id}"
    };
    window.treeCatalog = {};
</script>
</head>

<body>
<div id="manual-edit">
  <div id="tree-root" style="width: 300px;">
    <div class="nav-item-left">
      <i class="fa fa-th-large"></i> 目录
    </div>
    <div class="nav-item-right">
      <button data-target="#create-new" aria-haspopup="true" aria-expanded="false" id="create-document" title="创建文档">
      <i class="fa fa-plus"></i>
      </button>
    </div>
    <div class="nav-item-content" id="doc-sidebar" style="height:100%;overflow: auto"></div>
  </div>
  <form method="post" action="{:url('manual_doc/save')}" id="editormd-form">
    <div class="editormd-body">
      <div id="editormd">
        <input type="hidden" name="id" id="document-id">
        <textarea style="display:none;">### Hello</textarea>
      </div>
    </div>
  </form>
</div>
<!-- Modal -->
<div class="modal fade" id="create-wiki" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <form class="form-horizontal" role="form" method="post" action="{:url('manual_doc/save')}">
        <input type="hidden" name="manual_id" value="{$manual_id ? $manual_id : ''}">
        <input type="hidden" name="id" value="{$id ? $id : ''}">
        <input type="hidden" name="pid" value="{$pid ? $pid : 0}">
        <div class="modal-header">
          <h6 class="modal-title" id="modal-title">添加文件</h6>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label for="documentName" class="col-form-label">文档名称</label>
            <input type="text" name="documentName" class="form-control" id="documentName" placeholder="文档名称" />
          </div>
        </div>
        <div class="modal-footer">
          <span id="error-message" class="text-danger"></span>
          <button type="submit" class="btn btn-success" id="btn-action" data-loading-text="提交中...">确定</button>
          <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        </div>
      </form>
    </div>
  </div>
</div>
<div class="modal fade" id="template-modal" tabindex="-1" role="dialog" aria-labelledby="请选择模板类型" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <h6 class="modal-title" id="modal-title">请选择模板类型</h6>
      </div>
      <div class="modal-body">
        <div class="container clearfix">
          <div class="section">
            <a data-type="normal" href="javascript:;"><i class="fa fa-file-o"></i></a>
            <h3><a data-type="normal" href="javascript:;">普通文档</a></h3>
            <ul>
              <li>
                默认类型
              </li>
              <li>
                简单的文本文档
              </li>
            </ul>
          </div>
          <div class="section">
            <a data-type="api" href="javascript:;"><i class="fa fa-file-code-o"></i></a>
            <h3><a data-type="normal" href="javascript:;">API文档</a></h3>
            <ul>
              <li>
                用于API文档速写
              </li>
              <li>
                支持代码高亮
              </li>
            </ul>
          </div>
          <div class="section">
            <a data-type="code" href="javascript:;"><i class="fa fa-book"></i></a>
            <h3><a data-type="code" href="javascript:;">数据字典</a></h3>
            <ul>
              <li>
                用于数据字典显示
              </li>
              <li>
                表格支持
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
      </div>
    </div>
  </div>
</div>
<script type="text/plain" id="template-normal">
##光年后台模板是什么?
一个基于bootstrap的后台静态模板页面。

##光年整合了哪些插件？

-  bootstrap-table
-  webuploader
-  bootstrap-select
-  editormd
-  ...

</script>
<script type="text/plain" id="template-api">
### 简要描述：

- 用户登录接口

### 请求域名:

- http://xx.com

### 请求URL:

GET:/api/login

POST:/api/login

PUT:/api/login

DELETE:/api/login

TRACE:/api/login


### 参数:

|参数名|是否必须|类型|说明|
|:----    |:---|:----- |-----   |
|username |是  |string |用户名   |
|password |是  |string | 密码    |

### 返回示例:

**正确时返回:**

```
  {
    "errcode": 0,
    "data": {
      "uid": "1",
      "account": "admin",
      "nickname": "Minho",
      "group_level": 0 ,
      "create_time": "1436864169",
      "last_login_time": "0",
    }
  }
```

**错误时返回:**


```
  {
    "errcode": 500,
    "errmsg": "invalid appid"
  }
```

### 返回参数说明:

|参数名|类型|说明|
|:-----  |:-----|-----                           |
|group_level |int   |用户组id，1：超级管理员；2：普通用户  |

### 备注:

- 更多返回错误代码请看首页的错误代码描述



</script>
<script type="text/plain" id="template-code">
### 数据库字典
#### 用户表，储存用户信息

|字段|类型|空|默认|注释|
|:----    |:-------    |:--- |-- -|------      |
|uid	  |int(10)     |否	|	 |	           |
|username |varchar(20) |否	|    |	 用户名	|
|password |varchar(50) |否   |    |	 密码		 |
|name     |varchar(15) |是   |    |    昵称     |
|reg_time |int(11)     |否   | 0  |   注册时间  |

#### 备注：无
</script> 


{load href="/static/js/popper.min.js,/static/js/lyear-loading.min.js,/static/js/perfect-scrollbar.min.js" /}
{load href="/static/js/jquery-confirm/jquery-confirm.min.js,/static/js/bootstrap.min.js,/static/js/jquery.cookie.min.js" /}
{load href="/static/js/bootstrap-select/bootstrap-select.min.js,/static/js/bootstrap-select/i18n/defaults-zh_CN.min.js" /}
{load href="/static/js/jstree/jstree.js,/admin/js/jquery.form.js,/admin/js/json2.min.js" /}
{/* editormd原有的压缩文件，不知道啥没有file功能，这里采用未压缩的文件 */}
{load href="/static/js/editormd/editormd.js" /}
{load href="/static/js/app.min.js,/admin/js/main.min.js"}
<script type="text/javascript">
    /**
     * 初始化jstree
     */
    function initJsTree() {
        $("#doc-sidebar").jstree({
            'plugins': ['state', "wholerow", "types", 'dnd', 'contextmenu'],
            "types": {
                "default": {
                    "icon": false  // 删除默认图标
                },
            },
            'core': {
                'check_callback': true,
                'data': {$tree_json|raw},
                'animation': 0,
                "multiple": false
            },
            "contextmenu": {
                show_at_node: false,
                select_node: false,
                "items": {
                    "添加文档": {
                        "separator_before": false,
                        "separator_after": true,
                        "_disabled": false,
                        "label": "添加文档",
                        "icon": "fa fa-plus",
                        "action": function (data) {

                            var inst = $.jstree.reference(data.reference),
                                node = inst.get_node(data.reference);

                            openCreateCatalogDialog(node);
                            console.log(node);
                        }
                    },
                    "编辑": {
                        "separator_before": false,
                        "separator_after": true,
                        "_disabled": false,
                        "label": "编辑",
                        "icon": "fa fa-edit",
                        "action": function (data) {
                            var inst = $.jstree.reference(data.reference);
                            var node = inst.get_node(data.reference);
                            editDocumentDialog(node);
                        }
                    },
                    "删除": {
                        "separator_before": false,
                        "separator_after": true,
                        "_disabled": false,
                        "label": "删除",
                        "icon": "fa fa-trash-o",
                        "action": function (data) {
                            var inst = $.jstree.reference(data.reference);
                            var node = inst.get_node(data.reference);
                            deleteDocumentDialog(node);
                        }
                    }
                }
            }
        }).on('loaded.jstree', function () {
            window.treeCatalog = $(this).jstree();
            //console.log(window.treeCatalog);
        }).on('select_node.jstree', function (node, selected, event) {
            window.loadDocument(selected);

        }).on("move_node.jstree", function (node, parent) {

            var parentNode = window.treeCatalog.get_node(parent.parent);

            var nodeData = window.getSiblingSort(parentNode);

            if (parent.parent != parent.old_parent) {
                parentNode = window.treeCatalog.get_node(parent.old_parent);
                console.log(parentNode);
                var newNodeData = window.getSiblingSort(parentNode);
                if (newNodeData.length > 0) {
                    nodeData = nodeData.concat(newNodeData);
                }
            }

            var loader = $('body').lyearloading({
                opacity: 0.2,
                spinnerSize: 'lg'
            });

            $.post("{:url('manual_doc/sort', 'manual_id='.$manual_id)}", {'sortData' : JSON.stringify(nodeData)}).done(function (res) {
                loader.destroy();
                if (res.code == 1) {
                    showNotify("保存排序成功", 'success');
                } else {
                    showNotify(res.msg, 'danger');
                }
            }).fail(function () {
                loader.destroy();
                layer.msg("系统错误，请稍后再试");
            });
        });
    }
    $(function () {
        $("#template-modal .section>a").on("click",function () {
            var type = $(this).attr('data-type');
            if(type){
                var template = $("#template-" + type).text();
                window.editor.insertValue(template);
            }
            $("#template-modal").modal('hide');
        });
    });
</script> 
{load href="/admin/js/manual.min.js"}
</body>
</html>